package com.huawei.appgallery.updatemanager.impl.service;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import o.cdb;
import o.cdg;
import o.cei;
import o.czi;
import o.czk.g;
import o.czu;
import o.dao;
import o.dbn;
import o.dok;
import o.evk;

public class KeyAppUpdateDownloadService extends IntentService {
    public static final String DOWNLOAD_COMMAND = "downloadcommand";
    public static final int DOWNLOAD_COMMAND_ALL_UPDATE = 2;
    public static final int DOWNLOAD_COMMAND_KEY_APP = 1;
    public static final int DOWNLOAD_COMMAND_UNKNOW = 0;
    public static final String KEY_APP_UPDATE_DOWNLOAD_PRARM_PKG = "key_app_update_download_prarm_pkg";
    private Handler ˏ = new Handler();

    static class d implements Runnable {
        private Context ˏ;

        private d(Context context) {
            this.ˏ = context;
        }

        public void run() {
            evk.ˋ(this.ˏ, this.ˏ.getString(g.ˋ), 0).ˋ();
        }
    }

    public KeyAppUpdateDownloadService() {
        super("KeyAppUpdateDownloadService");
    }

    public KeyAppUpdateDownloadService(String str) {
        super(str);
    }

    public void onDestroy() {
        czi.ˎ.ˋ("KeyAppUpdateDS", "KeyAppUpdateDownloadService onDestroy()");
        super.onDestroy();
    }

    private static void ˋ(Context context) {
        try {
            Method method;
            Object systemService = context.getSystemService("statusbar");
            if (VERSION.SDK_INT <= 16) {
                method = systemService.getClass().getMethod("collapse", new Class[0]);
            } else {
                method = systemService.getClass().getMethod("collapsePanels", new Class[0]);
            }
            method.invoke(systemService, new Object[0]);
        } catch (NoSuchMethodException e) {
            czi.ˎ.ˊ("KeyAppUpdateDS", "collapse statusbar failed, NoSuchMethodException");
        } catch (IllegalAccessException e2) {
            czi.ˎ.ˊ("KeyAppUpdateDS", "collapse statusbar failed, IllegalAccessException");
        } catch (IllegalArgumentException e3) {
            czi.ˎ.ˊ("KeyAppUpdateDS", "collapse statusbar failed, IllegalArgumentException");
        } catch (InvocationTargetException e4) {
            czi.ˎ.ˊ("KeyAppUpdateDS", "collapse statusbar failed, InvocationTargetException");
        }
    }

    protected void onHandleIntent(Intent intent) {
        Intent safeIntent = new SafeIntent(intent);
        int intExtra = safeIntent.getIntExtra(DOWNLOAD_COMMAND, 0);
        if (1 == intExtra) {
            ˏ(safeIntent);
        } else if (2 == intExtra) {
            ॱ();
        }
    }

    private void ॱ() {
        ˋ(this);
        if (dok.ͺ()) {
            ˏ();
            if (dao.ˏ().ˎ() != null) {
                dao.ˏ().ˎ().ॱ(null);
                return;
            }
            return;
        }
        this.ˏ.post(new d(getApplicationContext()));
    }

    private void ˏ(Intent intent) {
        ˋ(this);
        Bundle extras = intent.getExtras();
        if (extras != null) {
            String string = extras.getString(KEY_APP_UPDATE_DOWNLOAD_PRARM_PKG);
            if (!TextUtils.isEmpty(string)) {
                ApkUpgradeInfo ॱ = ((czu) dbn.ˎ(czu.class)).ॱ(string, true, 1);
                int ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(string);
                if (ˋ == 1 || ˋ == 2) {
                    dao.ˏ().ˎ().ˎ(ॱ.ᐝ(), ॱ.ˊ(), ॱ.ॱᐝ());
                    ˏ();
                } else if (dok.ͺ()) {
                    ˏ();
                    if (dao.ˏ().ˎ() != null) {
                        dao.ˏ().ˎ().ॱ(string);
                    }
                } else {
                    this.ˏ.post(new d(getApplicationContext()));
                }
            }
        }
    }

    private void ˏ() {
        cei.ˋ(getApplicationContext(), "UpdateManager", 1020);
    }
}
